package top.yxqz.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Mr.余
 * @date 2022/11/10
 * @package top.yxqz.servlet
 */
public class ServletURLTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//  处理乱码
        response.setContentType("text/html;charset=utf-8");

//        除了服务器地址和端口号的部分
//        应用上下文开始的所有部分
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);
        int startIndex = uri.lastIndexOf("/");
        int length = uri.length();
        uri  =  uri.substring(startIndex,length);
        System.out.println("处理过后的字符串："+uri);
        PrintWriter writer = response.getWriter();
        if ("/user".equals(uri)){
            writer.print("普通用户");
        }
        if ("/vip.html".equals(uri)){
            writer.print("vip用户");
        }
        if ("/yxqz.svip".equals(uri)){
            writer.print("超级vip用户");
        }

//        关闭流
        writer.close();
    }
}
